<?php

namespace app\index\controller;

use think\Request;

use app\index\model\app as AppModel;

class App 
{
    
    public function getQiniuDomain(Request $request)
    {
        //无参请求

        //初始化消息
        $message = '';
        $status = 0;

        $appInfo = AppModel::get(['id' => 1]);

        //返回消息
        $JsonData = controller('index/JsonData');
        $json = $JsonData->getJsonData($status, $message, array('qiniuDomain' => $appInfo['qiniuDomain']));
        return $json;
    }
    public function getAppInfo(Request $request)
    {
        //无参请求
        
        //初始化消息
        $message = '';

        //获取信息
        $appInfo = AppModel::get(["id" => 1]);
        
        //设置消息，状态
        $message = $appInfo == NULL ? 'get appInfo fail.' : 'get appInfo success.';
        $status = $appInfo == NULL ? 1 : 0;

        //返回消息
        $JsonData = controller('index/JsonData');
        $json = $JsonData->getJsonData($status, $message, $appInfo);
        
        return $json;
    }

    public function updateAppInfo(Request $request)
    {
        //获取请求参数
        $appName = $request->param('appName');
        $subjectColor = $request->param('subjectColor');
        $appModel = $request->param('appModel');
        $askRule = $request->param('askRule');
        $chargeFee = $request->param('chargeFee');
        $appId = $request->param('appId');
        $appSecret = $request->param('appSecret');
        $qiniuAccessKey = $request->param('qiniuAccessKey');
        $qiniuSecretKey = $request->param('qiniuSecretKey');
        $qiniuBucket = $request->param('qiniuBucket');
        $qiniuDomain = $request->param('qiniuDomain');

        //初始化消息
        $message = '';
        $status = 0;
        
        //获取模型，更新数据
        $app = AppModel::get(["id" => 1]);
        $app->appName = $appName;
        $app->subjectColor = $subjectColor;
        $app->appModel = $appModel;
        $app->askRule = $askRule;
        $app->chargeFee = $chargeFee;
        $app->appId = $appId;
        $app->appSecret = $appSecret;
        $app->qiniuAccessKey = $qiniuAccessKey;
        $app->qiniuSecretKey = $qiniuSecretKey;
        $app->qiniuBucket = $qiniuBucket;
        $app->qiniuDomain = $qiniuDomain;

        if ($app->save()) {
            $message = 'update app info success.';
            $status = 0;
        }
        else {
            $message = 'no change.';
            $status = 0;
        }
        //返回数据
        $JsonData = controller('index/JsonData');
        $json = $JsonData->getJsonData($status, $message, array());
        return $json;
        
    }
}